package com.ruoyi.system.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ResponseReport;
import com.ruoyi.system.domain.TmcUser;
import com.ruoyi.system.mapper.ResponseReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.OneClickReportMapper;
import com.ruoyi.system.domain.OneClickReport;
import com.ruoyi.system.service.IOneClickReportService;

/**
 * 一键上报Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-01
 */
@Service
public class OneClickReportServiceImpl implements IOneClickReportService {
    @Autowired
    private OneClickReportMapper oneClickReportMapper;

    @Autowired
    private ResponseReportMapper responseReportMapper;

    /**
     * 查询一键上报
     *
     * @param oId 一键上报ID
     * @return 一键上报
     */
    @Override
    public OneClickReport selectOneClickReportById(Long oId) {
        return oneClickReportMapper.selectOneClickReportById(oId);
    }

    /**
     * 查询一键上报列表
     *
     * @param oneClickReport 一键上报
     * @return 一键上报
     */
    @Override
    public List<OneClickReport> selectOneClickReportList(OneClickReport oneClickReport) {
        return oneClickReportMapper.selectOneClickReportList(oneClickReport);
    }

    /**
     * 新增一键上报
     *
     * @param oneClickReport 一键上报
     * @return 结果
     */
    @Override
    public int insertOneClickReport(OneClickReport oneClickReport) {
        oneClickReport.setoCreattime(DateUtils.getNowDate());
        OneClickReport oneClickReport1 = oneClickReportMapper.selectOneClickReportByTime(oneClickReport.getPublicuserId());
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long diff = oneClickReport.getoCreattime().getTime() - oneClickReport1.getoCreattime().getTime();
        long day = diff / (24 * 60 * 60 * 1000);
        long hour = (diff / (60 * 60 * 1000) - day * 24);
        long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
        if (min > 5) {
            return oneClickReportMapper.insertOneClickReport(oneClickReport);
        } else {
            return 0;
        }
    }

    /**
     * 修改一键上报
     *
     * @param oneClickReport 一键上报
     * @return 结果
     */
    @Override
    public int updateOneClickReport(OneClickReport oneClickReport) {
        return oneClickReportMapper.updateOneClickReport(oneClickReport);
    }

    /**
     * 批量删除一键上报
     *
     * @param oIds 需要删除的一键上报ID
     * @return 结果
     */
    @Override
    public int deleteOneClickReportByIds(Long[] oIds) {
        return oneClickReportMapper.deleteOneClickReportByIds(oIds);
    }

    /**
     * 删除一键上报信息
     *
     * @param oId 一键上报ID
     * @return 结果
     */
    @Override
    public int deleteOneClickReportById(Long oId) {
        return oneClickReportMapper.deleteOneClickReportById(oId);
    }

    @Override
    public List<TmcUser> quweyfamily(Long publicuserId) {
        return oneClickReportMapper.quweyfamily(publicuserId);
    }

    /**
     * 新增一键上报
     *
     * @param responseReport 一键上报
     * @return 结果
     */
    @Override
    public int insertResponseReport(ResponseReport responseReport) {
        responseReport.setCreateTime(DateUtils.getNowDate());
        return responseReportMapper.insertResponseReport(responseReport);
    }
}
